package br.com.sampleProject.java;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.inject.Named;

import org.apache.commons.lang.RandomStringUtils;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import br.com.softplan.pd.zion.faces.impl.component.form.lookup.LookupContext;

@Named
@ViewAccessScoped
public class CardInputForm implements Serializable {

	private static final long serialVersionUID = 3847762478458272597L;
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	private ItemCardInput itemCardInput;
	private ItemCardInput itemPreenchido;
	private List<ItemCardInput> list;

	private String valorTeste;

	public CardInputForm() {
		this.setList(getItemList());
	}

	private List<ItemCardInput> getItemList() {
		List<ItemCardInput> list = new ArrayList<ItemCardInput>();
		for (int i = 0; i < 25; i++) {
			ItemCardInput item = new ItemCardInput();
			item.setId(i);
			item.setDescricao(RandomStringUtils.random(100, "abcdef ghijklm nopqrstuvx "));
			item.setNome(RandomStringUtils.random(10, "a bcde fghijkl mnopqr stuvxz "));
			list.add(item);
		}

		return list;
	}

	public List<ItemCardInput> lookupCardInputEditableSimple() {
		this.log.info(LookupContext.getLookupValue());
		return getList();
	}

	public List<ItemCardInput> lookupCardInputEditableWithInitialValueAndMapping() {
		this.log.info(LookupContext.getLookupValue());
		return getList();
	}

	public Collection<String> lookup() {

		String typedText = LookupContext.getLookupValue();
		System.out.println(typedText);
		if (typedText.equals("a")) {
			return Arrays.asList("abc", "aaa", "ab");
		}
		if (typedText.equals("b")) {
			return Arrays.asList("bc", "ab");
		}
		if (typedText.equals("c")) {
			return Arrays.asList("bc");
		}

		return Collections.emptyList();
	}

	public ItemCardInput getItemCardInput() {
		return this.itemCardInput;
	}

	public void setItemCardInput(final ItemCardInput itemCardInput) {
		this.itemCardInput = itemCardInput;
	}

	public ItemCardInput getItemPreenchido() {
		return this.itemPreenchido;
	}

	public void setItemPreenchido(final ItemCardInput itemPreenchido) {
		this.itemPreenchido = itemPreenchido;
	}

	public List<ItemCardInput> getList() {
		return this.list;
	}

	public void setList(final List<ItemCardInput> list) {
		this.list = list;
	}

	public String getValorTeste() {
		return this.valorTeste;
	}

	public void setValorTeste(final String valorTeste) {
		this.valorTeste = valorTeste;
	}
}
